<?php

namespace LaraPress\Sliver;

use LaraPress\Config\LaraPressCms;

class LaraPressSingle
{
    static function get_cover($post)
    {
        $cover = null;
        if (has_post_thumbnail($post)) {
            $cover = get_the_post_thumbnail_url($post);
        }
        if (!$cover) {
            $cover = LaraPressCms::get_option('cover');
            if ($cover) {
                $cover = $cover['url'];
            }
        }
        return $cover;
    }

    static function get_actions($post)
    {
        $actions = [];
        $actions["views"] = (int)get_post_meta($post->ID, 'larapress_views', true);
        $actions["likes"] = (int)get_post_meta($post->ID, 'larapress_likes', true);
        return $actions;
    }

    static function get_content_imgs($post)
    {
        $imgs = [];
        $content = $post->post_content;
        preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $matches);
        if ($matches) {
            $imgs = $matches[1];
        }
        return $imgs;
    }
}
